package com.qiku.controller;

import com.qiku.Student;
import com.qiku.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/stu")
public class StudentController {

    @Autowired
    private StudentService studentService;


    // 读取配置文件中的端口号 赋值给port
    @Value("${server.port}")
    private String port;

    @GetMapping("/port")
    public String port(){
        System.out.println("90001的port方法执行了。。。");
        return "9001端口号：" + port;
    }


    @RequestMapping("/query")
    public List<Student> findAll(){
        List<Student> list = studentService.list();
        return list;
    }


    @RequestMapping("/findById/{id}")
    public Student findById(@PathVariable Integer id){
        Student student = studentService.getById(id);
        return student;
    }


    @PostMapping("/add")
    public void addstu(@RequestBody Student student){

        studentService.save(student);


    }


    @RequestMapping("/update")
    public void UpdateStu(Student student){
        student.setId(5);
        student.setName("邓士载");
        student.setAge(17);
        student.setHome("义阳郡棘阳");
        studentService.updateById(student);

    }

//    @GetMapping("/updateByid/{id}")  不能用
//    public void UpdateStuById(@PathVariable Integer id){
//        Student student = new Student();
//        student.setId(id);
//        student.setName("士载");
//        student.setAge(16);
//        student.setHome("义阳郡棘阳");
//        studentService.updateById(student);
//
//    }



    @RequestMapping("/delete/{id}")
    public void deleteStu(@PathVariable Integer id){
        studentService.removeById(id);

    }







}
